<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :permission="permissionList"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      :page.sync="page"
      @row-update="rowUpdate"
      @row-save="rowSave"
      @row-del="rowDel"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot="menu" slot-scope="{ row, index }">
        <el-button
          type="text"
          size="small"
          icon="el-icon-edit"
          v-if="row.isFormula == 1"
          @click="$refs.crud.rowCellEdit(row, index)"
          >编辑
        </el-button></template
      >
      <template slot="menuLeft">
        <el-button
          type="danger"
          size="small"
          plain
          v-if="permission.wages_new"
          @click="handleNew"
          >生成新表
        </el-button>
        <el-button
          type="danger"
          size="small"
          plain
          v-if="permission.wages_settlement"
          @click="handleSettlement"
          >月结
        </el-button>
        <el-button
          type="danger"
          size="small"
          plain
          v-if="permission.wages_nosettlement"
          @click="handleNoSettlement"
          >反月结
        </el-button>
        <!-- <el-button
          type="danger"
          size="small"
          plain
          v-if="permission.wages_import"
          @click="handleImport"
          >数据导入
        </el-button> -->
        <el-dropdown>
          <el-button type="primary" size="small">
            数据导入<i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
          <el-dropdown-menu
            slot="dropdown"
            style="width: 200px; top: 218px; left: 336px"
          >
            <div
              class="btns"
              v-if="permission.wages_import"
              @click="handleImport"
            >
              数据导入
            </div>
            <div
              class="btns"
              v-if="permission.wages_down_template"
              @click="showTemplatess"
            >
              下载模版
            </div>
          </el-dropdown-menu>
        </el-dropdown>
        <el-dropdown>
          <el-button type="primary" size="small">
            特殊导入<i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
          <el-dropdown-menu
            slot="dropdown"
            style="width: 200px; top: 218px; left: 336px"
          >
            <div
              class="btns"
              v-if="permission.wages_import"
              @click="handleImports"
            >
              数据导入
            </div>
            <div
              class="btns"
              v-if="permission.wages_down_template"
              @click="downTemplate"
            >
              下载模版
            </div>
          </el-dropdown-menu>
        </el-dropdown>
        <el-button
          type="danger"
          size="small"
          plain
          v-if="permission.wages_export"
          @click="handleExport"
          >数据导出
        </el-button>
      </template>
      <template slot="deptId" slot-scope="{ row }">
        <div>{{ row.deptName }}</div>
      </template>
    </avue-crud>
    <div style="position: relative; width: 100%; height: 50px"></div>
    <el-dialog
      title="反月结"
      append-to-body
      :visible.sync="nosettlementBox"
      width="345px"
    >
      <div v-if="nosettlementBox">
        <div class="label">选择会计期间</div>
        <div class="date">
          <el-date-picker
            v-model="accountPeriod1"
            type="month"
            placeholder="选择月"
            format="yyyy-MM"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </div>
        <div class="tip">注：反月结后，目标会计期间月结数据会被清空！</div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="nosettlementBox = false">取 消</el-button>
          <el-button type="primary" @click="createSettlementBox"
            >确 定</el-button
          >
        </span>
      </div>
    </el-dialog>
    <el-dialog
      title="数据导出"
      append-to-body
      :visible.sync="exportBoolean"
      width="555px"
    >
      <avue-form
        v-if="exportBoolean"
        :option="exportBooleanOption"
        v-model="exportBooleanForm"
        @submit="submit"
      >
      </avue-form>
    </el-dialog>
    <el-dialog
      title="工资数据导入"
      append-to-body
      :visible.sync="excelBox"
      width="555px"
    >
      <avue-form
        v-if="excelBox"
        :option="excelOption"
        v-model="excelForm"
        :upload-before="uploadBefore"
        :upload-after="uploadAfter"
      >
        <!-- <template slot="excelTemplate">
          <div>
            <el-button type="primary" @click="handleTemplate">
              下载模板<i class="el-icon-download el-icon--right"></i>
            </el-button>
            <div class="downTip">
              说明：只有基于模版导入才可确保数据的正确性，如之前应用过标准模版，可忽略第一步直接导入。
            </div>
          </div>
        </template> -->
        <template slot="excelFile">
          <el-upload
            class="upload-demo"
            :show-file-list="false"
            :before-upload="uploadBefore"
            drag
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">
              将文件拖到此处，或<em>点击上传</em>
            </div>
            <div class="el-upload__tip" slot="tip">
              注：导入的数据会替换当前页面数据
            </div>
          </el-upload>
        </template>
      </avue-form>
    </el-dialog>
    <el-dialog
      title="工资数据导入"
      append-to-body
      :visible.sync="excelBoxs"
      width="555px"
    >
      <avue-form
        v-if="excelBoxs"
        :option="excelOptions"
        v-model="excelForms"
        :upload-before="uploadBefores"
        :upload-after="uploadAfters"
      >
        <!-- <template slot="excelTemplate">
          <div>
            <el-button type="primary" @click="handleTemplate">
              下载模板<i class="el-icon-download el-icon--right"></i>
            </el-button>
            <div class="downTip">
              说明：只有基于模版导入才可确保数据的正确性，如之前应用过标准模版，可忽略第一步直接导入。
            </div>
          </div>
        </template> -->
        <template slot="excelFile">
          <el-upload
            class="upload-demo"
            :show-file-list="false"
            :before-upload="uploadBefores"
            drag
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">
              将文件拖到此处，或<em>点击上传</em>
            </div>
            <div class="el-upload__tip" slot="tip">
              注：导入的数据会替换当前页面数据
            </div>
          </el-upload>
        </template>
      </avue-form>
    </el-dialog>
    <el-dialog
      title="生成新表"
      append-to-body
      :visible.sync="showTable"
      width="345px"
    >
      <div v-if="showTable">
        <div class="label">选择会计期间</div>
        <div class="date">
          <el-date-picker
            v-model="accountPeriod"
            type="month"
            placeholder="选择月"
            format="yyyy-MM"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </div>
        <div class="tip">注：新表沿用上一次已月结数据</div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="showTable = false">取 消</el-button>
          <el-button type="primary" @click="createTable">确 定</el-button>
        </span>
      </div>
    </el-dialog>
    <el-dialog
      title="下载模版"
      append-to-body
      :visible.sync="showTemplate"
      width="40%"
    >
      <div v-if="showTemplate">
        <div style="padding-bottom: 20px">选择字段</div>
        <div>
          <el-checkbox-group v-model="checkList">
            <el-checkbox
              v-for="item in templateList"
              :label="item.key"
              :value="item.key"
              :key="item.key"
              >{{ item.name }}</el-checkbox
            >
          </el-checkbox-group>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="showTemplate = false">取 消</el-button>
          <el-button type="primary" @click="exportParam">下载模版</el-button>
        </span>
      </div>
    </el-dialog>
  </basic-container>
</template>

<script>
import {
  getList,
  getDetail,
  add,
  update,
  remove,
  settlement,
  batchAdd,
  nosettlement,
  importWages,
  getExportParam,
  importWageNon,
} from "@/api/wages/wages";
import { mapGetters } from "vuex";
import { getDeptTree } from "@/api/system/dept";
import { getToken } from "@/util/auth";
import axios from "axios";
export default {
  data() {
    return {
      checkList: [],
      templateList: [],
      showTemplate: false,
      showTable: false,
      accountPeriod: "",
      accountPeriod1: "",
      form: {},
      query: {},
      excelBox: false,
      nosettlementBox: false,
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      excelOption: {
        submitBtn: false,
        emptyBtn: false,
        column: [
          // {
          //   label: "第一步",
          //   prop: "excelTemplate",
          //   formslot: true,
          //   span: 24,
          //   // tipPlacement: "注：导入的数据会替换当前页面数据",
          //   // tip: "注：导入的数据会替换当前页面数据",
          //   // labelTip: "注：导入的数据会替换当前页面数据",
          //   // labelTipPlacement: "123",
          // },
          {
            label: "会计期间",
            prop: "accountPeriod",
            type: "month",
            format: "yyyy-MM",
            valueFormat: "yyyy-MM",
            rules: [
              {
                required: true,
                message: "请输入会计期间",
                trigger: "blur",
              },
            ],
          },
          {
            label: "",
            prop: "excelFile",
            // type: "upload",
            // drag: true,
            // loadText: "模板上传中，请稍等",
            // propsHttp: {
            //   res: "data",
            // },
            // tip: "注：导入的数据会替换当前页面数据",
            // action: "/api/blade-wages/wages/import-wages",
            span: 24,
            labelWidth: 0,
            formslot: true,
          },
        ],
      },
      excelBoxs: false,
      excelForm: {},
      excelOptions: {
        submitBtn: false,
        emptyBtn: false,
        column: [
          // {
          //   label: "第一步",
          //   prop: "excelTemplate",
          //   formslot: true,
          //   span: 24,
          //   // tipPlacement: "注：导入的数据会替换当前页面数据",
          //   // tip: "注：导入的数据会替换当前页面数据",
          //   // labelTip: "注：导入的数据会替换当前页面数据",
          //   // labelTipPlacement: "123",
          // },
          {
            label: "会计期间",
            prop: "accountPeriod",
            type: "month",
            format: "yyyy-MM",
            valueFormat: "yyyy-MM",
            rules: [
              {
                required: true,
                message: "请输入会计期间",
                trigger: "blur",
              },
            ],
          },
          {
            label: "",
            prop: "excelFile",
            // type: "upload",
            // drag: true,
            // loadText: "模板上传中，请稍等",
            // propsHttp: {
            //   res: "data",
            // },
            // tip: "注：导入的数据会替换当前页面数据",
            // action: "/api/blade-wages/wages/import-wages",
            span: 24,
            labelWidth: 0,
            formslot: true,
          },
        ],
      },
      excelForms: {},
      option: {
        height: "auto",
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        align: "center",
        border: true,
        index: true,
        cellBtn: true,
        viewBtn: true,
        selection: false,
        dialogClickModal: false,
        sumText: "合计",
        showSummary: true,
        editBtn: false,
        sumColumnList: [
          {
            label: "合计：",
            name: "postWages",
            type: "sum",
          },
          {
            label: " ",
            name: "levelWages",
            type: "sum",
          },
          {
            label: " ",
            name: "lifeAllowance",
            type: "sum",
          },
          {
            label: " ",
            name: "workAllowance",
            type: "sum",
          },
          {
            label: " ",
            name: "remoteAreas",
            type: "sum",
          },
          {
            label: " ",
            name: "rescueAllowance",
            type: "sum",
          },
          {
            label: " ",
            name: "dutyAllowance",
            type: "sum",
          },
          {
            label: " ",
            name: "sceneAllowance",
            type: "sum",
          },
          {
            label: " ",
            name: "otherAllowance",
            type: "sum",
          },
          {
            label: " ",
            name: "dayWages",
            type: "sum",
          },
          {
            label: " ",
            name: "workNum",
            type: "sum",
          },
          {
            label: " ",
            name: "reissue",
            type: "sum",
          },
          {
            label: " ",
            name: "achievementBonus",
            type: "sum",
          },
          {
            label: " ",
            name: "payableTotal",
            type: "sum",
          },
          {
            label: " ",
            name: "deductingSocial",
            type: "sum",
          },
          {
            label: " ",
            name: "actualTotal",
            type: "sum",
          },
        ],
        column: [
          {
            label: "会计期间",
            prop: "accountPeriod",
            type: "month",
            format: "yyyy-MM",
            valueFormat: "yyyy-MM-dd HH:mm:ss",
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入会计期间",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "所属组织",
            prop: "deptId",
            search: true,
            type: "tree",
            // cell: true,
            addDisabled: false,
            width: 300,
            // slot: true,
            dicUrl: "/api/fine-system/dept/tree",
            props: {
              label: "title",
              value: "value",
            },
            dicFormatter: (res) => {
              return res.data;
            },
            rules: [
              {
                required: true,
                message: "请输入所属组织id",
                trigger: "blur",
              },
            ],
          },
          // {
          //   label: "所属组织",
          //   prop: "deptName",
          //   rules: [{
          //     required: true,
          //     message: "请输入所属组织",
          //     trigger: "blur"
          //   }]
          // },
          {
            label: "姓名",
            prop: "name",
            search: true,
            // cell: true,
            rules: [
              {
                required: true,
                message: "请输入姓名",
                trigger: "blur",
              },
            ],
          },
          {
            label: "工资保障",
            prop: "protection",
            type: "select",
            dicUrl: "/api/fine-system/dict/dictionary?code=guarantee",
            props: {
              label: "dictValue",
              value: "dictKey",
            },
            search: true,
            showColumn: false,
            dataType: "number",
            rules: [
              {
                required: true,
                message: "请选择工资保障",
                trigger: "blur",
              },
            ],
          },
          {
            label: "身份证",
            prop: "idCard",
            // cell: true,
            width: 200,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入身份证",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "套改等级",
            prop: "levelName",
            // cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入套改等级",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "岗位",
            prop: "postName",
            // cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入岗位",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "职位",
            prop: "position",
            // cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入职位",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "银行卡号",
            prop: "bankNo",
            width: 200,
            // cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入银行卡号",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "岗位/职务工资",
            prop: "postWages",
            // cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入岗位/职务工资",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "等级工资",
            prop: "levelWages",
            // cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入等级工资",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "工作性津贴",
            prop: "workAllowance",
            // cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入工作性津贴",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "工资性津贴",
            prop: "lifeAllowance",
            // cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入工资性津贴",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "艰苦边远津贴",
            prop: "remoteAreas",
            // cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入艰苦边远津贴",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "消防救援津贴(扣除750元绩效奖金)",
            prop: "rescueAllowance",
            // cell: true,
            width: 150,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入消防救援津贴(扣除750元绩效奖金)",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "消防执勤补贴",
            prop: "dutyAllowance",
            cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入消防执勤补贴",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "现场救援补贴",
            prop: "sceneAllowance",
            cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入现场救援补贴",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "其他补贴",
            prop: "otherAllowance",
            cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入其他补贴",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "天工资",
            prop: "dayWages",
            cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入天工资",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "工作天数",
            prop: "workNum",
            cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入工作天数",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "补发",
            prop: "reissue",
            cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入补发",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "补发备注",
            prop: "reissueNote",
            cell: true,
            // rules: [
            //   {
            //     required: false,
            //     message: "请输入补发备注",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "绩效奖金",
            prop: "achievementBonus",
            cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入绩效奖金",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "应发合计",
            prop: "payableTotal",
            // cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入应发合计",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "扣除社保个人部分",
            prop: "deductingSocial",
            cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入扣除社保个人部分",
            //     trigger: "blur",
            //   },
            // ],
          },
          // {
          //   label: "个税专项扣除部分",
          //   prop: "deductingSpecial",
          //   cell: true,
          //   // rules: [
          //   //   {
          //   //     required: true,
          //   //     message: "请输入个税专项扣除部分",
          //   //     trigger: "blur",
          //   //   },
          //   // ],
          // },
          // {
          //   label: "个税实缴金额",
          //   prop: "paidIn",
          //   // rules: [
          //   //   {
          //   //     required: true,
          //   //     message: "请输入个税实缴金额",
          //   //     trigger: "blur",
          //   //   },
          //   // ],
          // },
          // {
          //   label: "个税实缴档位",
          //   prop: "paidLevel",
          //   // cell: true,
          //   // rules: [
          //   //   {
          //   //     required: true,
          //   //     message: "请输入个税实缴档位",
          //   //     trigger: "blur",
          //   //   },
          //   // ],
          // },
          // {
          //   label: "个税实缴比例",
          //   prop: "paidProp",
          //   // cell: true,
          //   // rules: [
          //   //   {
          //   //     required: true,
          //   //     message: "请输入个税实缴比例",
          //   //     trigger: "blur",
          //   //   },
          //   // ],
          // },
          // {
          //   label: "个税缴纳金额",
          //   prop: "paidAmount",
          //   // cell: true,
          //   // rules: [
          //   //   {
          //   //     required: true,
          //   //     message: "请输入个税缴纳金额",
          //   //     trigger: "blur",
          //   //   },
          //   // ],
          // },
          {
            label: "实发合计",
            prop: "actualTotal",
            // cell: true,
            // rules: [
            //   {
            //     required: true,
            //     message: "请输入实发合计",
            //     trigger: "blur",
            //   },
            // ],
          },
          {
            label: "备注",
            prop: "note",
            cell: true,
            // rules: [
            //   {
            //     required: false,
            //     message: "请输入备注",
            //     trigger: "blur",
            //   },
            // ],
          },
        ],
      },
      data: [],
      exportBoolean: false,
      exportBooleanForm: {},
      exportBooleanOption: {
        // submitBtn: false,
        // emptyBtn: false,
        column: [
          {
            label: "工资保障",
            prop: "protection",
            type: "select",
            dicUrl: "/api/fine-system/dict/dictionary?code=guarantee",
            props: {
              label: "dictValue",
              value: "dictKey",
            },
            search: true,
            span: 24,
            showColumn: false,
            dataType: "number",
            rules: [
              {
                required: true,
                message: "请选择工资保障",
                trigger: "blur",
              },
            ],
          },
        ],
      },
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        addBtn: false,
        viewBtn: false,
        delBtn: this.vaildData(this.permission.wages_delete, false),
        editBtn: this.vaildData(this.permission.wages_edit, false),
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
  },
  mounted() {
    this.initData();
  },
  methods: {
    rowEdit(row, index) {
      console.log(this.$refs.crud.rowCellEdit(row, index));
    },
    exportParam() {
      if (this.checkList.length < 1)
        return this.$message({
          type: "error",
          message: "请先选择字段！",
        });
      let fields = this.checkList.join(",");
      axios({
        url: `/api/blade-wages/wages/export-template?fields=${fields}`,
        method: "get",
        responseType: "blob",
      }).then((res) => {
        this.showTemplate = false;
        this.checkList = [];
        let url = window.URL.createObjectURL(new Blob([res.data]));
        let a = document.createElement("a");
        a.style.display = "none";
        a.href = url;
        let title = "下载模版.xlsx";
        a.setAttribute("download", title);
        document.body.appendChild(a);
        a.click(); //执行下载
        window.URL.revokeObjectURL(a.href); // 清除url
        document.body.removeChild(a); //移除dom
      });
    },
    showTemplatess() {
      getExportParam().then((res) => {
        this.templateList = res.data.data;
        this.showTemplate = true;
        this.checkList = [];
      });
    },
    downTemplate() {
      axios({
        url: `/api/blade-wages/wages/export-non-template`,
        method: "get",
        responseType: "blob",
      }).then((res) => {
        this.showTemplate = false;
        this.checkList = [];
        let url = window.URL.createObjectURL(new Blob([res.data]));
        let a = document.createElement("a");
        a.style.display = "none";
        a.href = url;
        let title = "下载模版.xlsx";
        a.setAttribute("download", title);
        document.body.appendChild(a);
        a.click(); //执行下载
        window.URL.revokeObjectURL(a.href); // 清除url
        document.body.removeChild(a); //移除dom
      });
    },
    handleTemplate() {
      window.open(
        `/api/blade-wages/wages/export-template?${
          this.website.tokenHeader
        }=${getToken()}&status=0`
      );
    },
    // 反月结
    createSettlementBox() {
      nosettlement(this.accountPeriod1).then((res) => {
        if (res.data.code == 200) {
          this.accountPeriod1 = "";
          this.nosettlementBox = false;
          this.onLoad(this.page);
        }
      });
    },
    handleNoSettlement() {
      this.accountPeriod1 = "";
      this.nosettlementBox = true;
    },
    //生成新表
    createTable() {
      // accountPeriod
      batchAdd(this.accountPeriod).then((res) => {
        if (res.data.code == 200) {
          this.accountPeriod = "";
          this.showTable = false;
          this.onLoad(this.page);
        }
      });
    },
    handleNew() {
      this.accountPeriod = "";
      this.showTable = true;
    },
    handleSettlement() {
      settlement().then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        },
        (error) => {
          window.console.log(error);
        }
      );
    },
    handleImport() {
      this.excelBox = true;
    },
    uploadAfter(res, done, loading, column) {
      window.console.log(column);
      this.excelBox = false;
      this.refreshChange();
      done();
    },
    uploadBefore(file) {
      if (!this.excelForm.accountPeriod)
        return this.$message.error("请先选择会计期间!");
      importWages(file, this.excelForm.accountPeriod).then(() => {
        this.excelBox = false;
        this.excelForm = {};
        this.onLoad(this.page);
      });
    },
    handleImports() {
      this.excelBoxs = true;
    },
    uploadAfters(res, done, loading, column) {
      window.console.log(column);
      this.excelBoxs = false;
      this.refreshChange();
      done();
    },
    uploadBefores(file) {
      if (!this.excelForms.accountPeriod)
        return this.$message.error("请先选择会计期间!");
      importWageNon(file, this.excelForms.accountPeriod).then(() => {
        this.excelBoxs = false;
        this.excelForms = {};
        this.onLoad(this.page);
      });
    },
    submit(form, done) {
      done();
      this.exportBoolean = false;
      if (this.data.length != 0) {
        window.open(
          `/api/blade-wages/wages/export-wages-base?${
            this.website.tokenHeader
          }=${getToken()}&status=0&protection=${form.protection}`
        );
      } else {
        this.$message.warning("当前无数据，按钮不可用");
        return;
      }
    },
    handleExport() {
      this.exportBoolean = true;
      // if (this.data.length != 0) {
      //   window.open(
      //     `/api/blade-wages/wages/export-wages-base?${
      //       this.website.tokenHeader
      //     }=${getToken()}&status=0`
      //   );
      // } else {
      //   this.$message.warning("当前无数据，按钮不可用");
      //   return;
      // }
    },
    initData() {
      getDeptTree().then((res) => {
        const column = this.findObject(this.option.column, "deptId");
        column.dicData = res.data.data;
      });
    },
    rowSave(row, done, loading) {
      let obj = {
        dutyAllowance: row.dutyAllowance,
        sceneAllowance: row.sceneAllowance,
        otherAllowance: row.otherAllowance,
        dayWages: row.dayWages,
        workNum: row.workNum,
        reissue: row.reissue,
        reissueNote: row.reissueNote,
        achievementBonus: row.achievementBonus,
        deductingSocial: row.deductingSocial,
        // deductingSpecial: row.deductingSpecial,
        idCard: row.idCard,
        // paidLevel: row.paidLevel,
        // paidProp: row.paidProp,
        note: row.note,
      };
      add(obj).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
        },
        (error) => {
          loading();
          window.console.log(error);
        }
      );
    },
    rowUpdate(row, index, done, loading) {
      let obj = {
        id: row.id,
        dutyAllowance: row.dutyAllowance,
        sceneAllowance: row.sceneAllowance,
        otherAllowance: row.otherAllowance,
        dayWages: row.dayWages,
        workNum: row.workNum,
        reissue: row.reissue,
        reissueNote: row.reissueNote,
        achievementBonus: row.achievementBonus,
        deductingSocial: row.deductingSocial,
        // deductingSpecial: row.deductingSpecial,
        idCard: row.idCard,
        // paidLevel: row.paidLevel,
        // paidProp: row.paidProp,
        note: row.note,
      };
      update(obj).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
        },
        (error) => {
          loading();
          console.log(error);
        }
      );
    },
    rowDel(row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        });
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(this.ids);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          this.$refs.crud.toggleSelection();
        });
    },
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        getDetail(this.form.id).then((res) => {
          this.form = res.data.data;
        });
      }
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      params.status = 0;
      getList(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      )
        .then((res) => {
          const data = res.data.data;
          // console.log(this.actionData(data.records), "acyionData");
          this.page.total = 100;
          this.data = data;
          this.loading = false;
          this.selectionClear();
        })
        .catch(() => {
          this.data = [];
          this.loading = false;
        });
    },
  },
};
</script>

<style scoped lang="scss">
/deep/.avue-crud__pagination {
  visibility: hidden;
}
/deep/.el-checkbox {
  padding-bottom: 20px;
}
.btns {
  font-size: 16px;
  text-align: center;
  padding-top: 10px;
  padding-bottom: 10px;
}
.downTip {
  padding-top: 15px;
  font-size: 12px;
  font-family: Source Han Sans, Source Han Sans;
  font-weight: 400;
  color: #666666;
  line-height: 18px;
}
/deep/.el-dialog__header {
  text-align: center;
  font-size: 24px;
  font-family: Source Han Sans, Source Han Sans;
  font-weight: 600;
  color: #000000;
  border-bottom: 1px solid #d8d8d8;
}

/deep/.el-dialog__footer {
  width: 100%;
  display: flex;
}
/deep/.dialog-footer {
  padding-top: 15px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
}
.label {
  font-size: 16px;
  font-family: Source Han Sans, Source Han Sans;
  font-weight: 400;
  color: #666666;
  width: 100%;
  text-align: center;
}
.date {
  padding-top: 16px;
  width: 100%;
  margin: 0 auto;
  height: 32px;
  border-radius: 2px 2px 2px 2px;
  text-align: center;
  .el-date-editor--month {
    width: 161px;
    height: 100%;
  }
}
.tip {
  padding-top: 20px;
  width: 100%;
  text-align: center;
}
</style>
